using System;
using System.Data;
using Common.Enumerations;
using Sanelib.DataOperation;
using Sanelib.DataOperation.Attribute;
using Sanelib.DataOperation.Base;
using Sanelib.Dto.Enumerations;

namespace Core.Domain.Model
{
    [EntityName("Account")]
    public class Account : AuditedEntity
    {
        public AccountType AccountType { get; set; }
        public string AccountNumber { get; set; }
        public Industry Industry { get; set; }
        public string BillingStreet { get; set; }
        public string BillingCity { get; set; }
        public string BillingState { get; set; }
        public string BillingPostalCode { get; set; }
        public string BillingCountry { get; set; }
        public decimal? BillingLatitude { get; set; }
        public decimal? BillingLongitude { get; set; }
        public string ShippingStreet { get; set; }
        public string ShippingCity { get; set; }
        public string ShippingState { get; set; }
        public string ShippingPostalCode { get; set; }
        public string ShippingCountry { get; set; }
        public decimal? ShippingLatitude { get; set; }
        public decimal? ShippingLongitude { get; set; }
        public string Phone { get; set; }
        public string Mobile { get; set; }
        public string Fax { get; set; }
        public string Website { get; set; }
        public string Email { get; set; }

        public override void From(IDataReader dataReader)
        {
            base.From(dataReader);
            AccountType = AccountType.FromValue(dataReader.ReadNullSafeString("AccountTypeValue"));
            AccountNumber = dataReader.ReadNullSafeString("AccountNumber");
            Industry = Industry.FromValue(dataReader.ReadNullSafeString("IndustryTypeValue"));
            BillingStreet = dataReader.ReadNullSafeString("BillingStreet");
            BillingCity = dataReader.ReadNullSafeString("BillingCity");
            BillingState = dataReader.ReadNullSafeString("BillingState");
            BillingPostalCode = dataReader.ReadNullSafeString("BillingPostalCode");
            BillingCountry = dataReader.ReadNullSafeString("BillingCountry");
            BillingLatitude = dataReader.ReadNullSafeDecimal("BillingLatitude");
            BillingLongitude = dataReader.ReadNullSafeDecimal("BillingLongitude");
            ShippingStreet = dataReader.ReadNullSafeString("ShippingStreet");
            ShippingCity = dataReader.ReadNullSafeString("ShippingCity");
            ShippingState = dataReader.ReadNullSafeString("ShippingState");
            ShippingPostalCode = dataReader.ReadNullSafeString("ShippingPostalCode");
            ShippingCountry = dataReader.ReadNullSafeString("ShippingCountry");
            ShippingLatitude = dataReader.ReadNullSafeDecimal("ShippingLatitude");
            ShippingLongitude = dataReader.ReadNullSafeDecimal("ShippingLongitude");
            Phone = dataReader.ReadNullSafeString("Phone");
            Mobile = dataReader.ReadNullSafeString("Mobile");
            Fax = dataReader.ReadNullSafeString("Fax");
            Website = dataReader.ReadNullSafeString("Website");
            Email = dataReader.ReadNullSafeString("Email");
        }

        public override void To(System.Data.SqlClient.SqlCommand cmd)
        {
            base.To(cmd);
            cmd.Parameters.Add("@AccountTypeValue", SqlDbType.Char, 2).Value = BaseEnumeration.GetDbNullSafe(AccountType);
            cmd.Parameters.Add("@AccountNumber", SqlDbType.VarChar).Value = AccountNumber;
            cmd.Parameters.Add("@IndustryTypeValue", SqlDbType.NVarChar).Value = BaseEnumeration.GetDbNullSafe(Industry);
            cmd.Parameters.Add("@BillingStreet", SqlDbType.NVarChar).Value = (object)BillingStreet ?? DBNull.Value;
            cmd.Parameters.Add("@BillingCity", SqlDbType.NVarChar).Value = (object)BillingCity ?? DBNull.Value;
            cmd.Parameters.Add("@BillingState", SqlDbType.NVarChar).Value = (object)BillingState ?? DBNull.Value;
            cmd.Parameters.Add("@BillingPostalCode", SqlDbType.VarChar).Value = (object)BillingPostalCode ?? DBNull.Value;
            cmd.Parameters.Add("@BillingCountry", SqlDbType.NVarChar).Value = (object)BillingCountry ?? DBNull.Value;
            cmd.Parameters.Add("@BillingLatitude", SqlDbType.Decimal).Value = (object)BillingLatitude ?? DBNull.Value;
            cmd.Parameters.Add("@BillingLongitude", SqlDbType.Decimal).Value = (object)BillingLongitude ?? DBNull.Value;
            cmd.Parameters.Add("@ShippingStreet", SqlDbType.NVarChar).Value = (object)ShippingStreet ?? DBNull.Value;
            cmd.Parameters.Add("@ShippingCity", SqlDbType.NVarChar).Value = (object)ShippingCity ?? DBNull.Value;
            cmd.Parameters.Add("@ShippingState", SqlDbType.NVarChar).Value = (object)ShippingState ?? DBNull.Value;
            cmd.Parameters.Add("@ShippingPostalCode", SqlDbType.VarChar).Value = (object)ShippingPostalCode ?? DBNull.Value;
            cmd.Parameters.Add("@ShippingCountry", SqlDbType.NVarChar).Value = (object)ShippingCountry ?? DBNull.Value;
            cmd.Parameters.Add("@ShippingLatitude", SqlDbType.Decimal).Value = (object)ShippingLatitude ?? DBNull.Value;
            cmd.Parameters.Add("@ShippingLongitude", SqlDbType.Decimal).Value = (object)ShippingLongitude ?? DBNull.Value;
            cmd.Parameters.Add("@Phone", SqlDbType.VarChar).Value = (object)Phone ?? DBNull.Value;
            cmd.Parameters.Add("@Mobile", SqlDbType.VarChar).Value = (object)Mobile ?? DBNull.Value;
            cmd.Parameters.Add("@Fax", SqlDbType.VarChar).Value = (object)Fax ?? DBNull.Value;
            cmd.Parameters.Add("@Website", SqlDbType.VarChar).Value = (object)Website ?? DBNull.Value;
            cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = (object)Email ?? DBNull.Value;
        }
    }
}
